package online.szlib.com.core.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import online.szlib.com.core.domain.Order;
import online.szlib.com.core.repositories.OrderRepository;

@Service("orderService")
public class OrderServiceImpl implements OrderService {
	
	@Autowired
	private OrderRepository orderRepository;
	
	public void addOrder(Order order) {
		orderRepository.save(order);
	}

	public Order getOrder(Long orderId){
		return orderRepository.findOne(orderId);
	}
	
	public List<Order> listOrders() {
		return orderRepository.findAll();
	}
	
	public void deleteOrder(Order order){
		orderRepository.delete(order);
	}
	
	public Long create(Order order){
		orderRepository.saveAndFlush(order);
		return 1L;
	}
	
	public void update(Order order) {
		orderRepository.saveAndFlush(order);
		System.out.println("Update one order:" + order);
	}
	
	public void deleteById(Long id) {
		Order order = orderRepository.findOne(id);
		orderRepository.delete(order);
	}
	
}
